home *** CD-ROM | disk | FTP | other *** search
- Path: owl.WPI.EDU!kevint
- From: kevint@wpi.edu (Kevin Theroux)
- Newsgroups: comp.lang.c++
- Subject: OWL: Palette problem - Please HELP!
- Date: 30 Jan 1996 20:25:44 GMT
- Organization: Worcester Polytechnic Institute
- Message-ID: <4elus8$e5m@bigboote.WPI.EDU>
- NNTP-Posting-Host: owl.wpi.edu
- X-Newsreader: TIN [version 1.2 PL1]
-
-
-
- Hi there,
- I hope someone out there can help...I'm really stuck and in a time cruch.
-
- I am taking a course in Graphics and decided to use the PC for my projects.
- I just need to get a bare-bones app going so I can do my project. I want
- to create a simple window, create a bitmap in the window (so I can draw
- to it), create a palette (aka color map) and get access to the palette to
- change colors.
-
- I have everything working EXCEPT creating and modifying a palette.
- Can someome PLEASE help me out with this. My code is below.
- If you already have a skeleton app that does what I'm looking for,
- could you please email it to me or tell me what I did wrong?
- (kevint@cs.wpi.edu)
-
- The code I have for creating a palette came directly from a Borland
- example...but it doesn't work. I'm using Borland C++ v4.5.
-
- Thank you,
- Kevin Theroux :-)
-
- ============================================================================
-
- #include <owl/owlpch.h>
- #include <owl/applicat.h>
- #include <owl/framewin.h>
- #include <owl/dc.h>
- #include <owl/inputdia.h>
- #include <owl/color.h>
- #include <stdlib.h>
-
- /*------------------------------------------------------------------------*/
-
- #define NUM_PALETTE_ENTRIES 128
-
- /*------------------------------------------------------------------------*/
-
- int width, height;
- HPALETTE hpal;
- PALETTEENTRY ape[NUM_PALETTE_ENTRIES];
- LOGPALETTE* plgpl;
-
- /*------------------------------------------------------------------------*/
-
- class myWindow : public TWindow
- {
- TMemoryDC *myMemoryBitmap; // this is where to draw to, then it is
- // BitBlt'ed to the window
-
- public:
- myWindow(TWindow* parent = 0);
- void SetupWindow();
- ~myWindow()
- {
- }
-
- protected:
- // Message response functions
-
- void Paint(TDC& dc, BOOL erase, TRect& rect);
- };
-
- /*------------------------------------------------------------------------*/
-
- myWindow::myWindow(TWindow* parent)
- {
- Init(parent, 0, 0);
- }
-
- /*------------------------------------------------------------------------*/
-
- void
- myWindow::Paint(TDC& dc, BOOL, TRect& )
- {
- dc.BitBlt( GetClientRect(), *myMemoryBitmap, TPoint(0,0));
- }
-
- /*------------------------------------------------------------------------*/
-
- void
- myWindow::SetupWindow()
- {
- int i, j, k, red, green, blue;
-
- TWindow::SetupWindow();
-
- myMemoryBitmap = new TMemoryDC( TClientDC (HWindow));
- myMemoryBitmap->SelectObject (TBitmap (width, height, 1, 32));
-
- plgpl = (LOGPALETTE*) LocalAlloc (LPTR,
- sizeof(LOGPALETTE) + NUM_PALETTE_ENTRIES * sizeof(PALETTEENTRY));
-
- plgpl->palNumEntries = NUM_PALETTE_ENTRIES;
- plgpl->palVersion = 0x300;
-
- for (i = 0, red = 0, green = 127, blue = 127; i < NUM_PALETTE_ENTRIES;
- i++, red += 1, green += 1, blue += 1)
- {
- ape[i].peRed = plgpl->palPalEntry[i].peRed = LOBYTE(red);
- ape[i].peGreen = plgpl->palPalEntry[i].peGreen = LOBYTE(green);
- ape[i].peBlue = plgpl->palPalEntry[i].peBlue = LOBYTE(blue);
- ape[i].peFlags = plgpl->palPalEntry[i].peFlags = PC_RESERVED;
- }
-
- hpal = CreatePalette(plgpl); // * * THIS ALWAYS RETURNS NULL * *
-
- AnimatePalette(hpal, 0, NUM_PALETTE_ENTRIES,
- (PALETTEENTRY FAR*) &ape);
- }
-
- /*------------------------------------------------------------------------*/
-
- class myApp : public TApplication {
- public:
- myApp() : TApplication() {}
-
- void InitMainWindow()
- {
- TFrameWindow *my_FrameWindow = \
- new TFrameWindow(0, "Draw", new myWindow(0), true);
-
- width = TScreenDC().GetDeviceCaps( HORZRES );
- height = TScreenDC().GetDeviceCaps( VERTRES );
-
- my_FrameWindow->Attr.X = (width -600)/2;
- my_FrameWindow->Attr.Y = (height-400)/2-20;
-
- SetMainWindow (my_FrameWindow);
- }
- };
-
- /*------------------------------------------------------------------------*/
-
- int
- OwlMain(int /*argc*/, char* /*argv*/ [])
- {
- return myApp().Run();
- }
-
- /*------------------------------------------------------------------------*/
-